package com.shujia


class Demo08ScalaClassConstruct(id: String, name: String, age: Int) { // 默认的构造方法
  println("默认的构造器")
  // 在Scala的类中定义属性，一般以下划线开头来命名
  // 定义即赋值，定义属性的时候必须进行赋值
  val _id: String = id
  val _name: String = name
  val _age: Int = age
  var _gender: String = "男"
  var _clazz: String = _ // 稍后再进行赋值

  // 辅助构造器
  def this(id: String, name: String, age: Int, gender: String) {
    // 第一行代码必须调用默认的构造器
    this(id, name, age)
    _gender = gender
    println("调用了辅助构造器1")
  }

  // 辅助构造器
  def this(id: String, name: String, age: Int, gender: String, clazz: String) {
    // 第一行代码必须调用默认的构造器
    this(id, name, age, gender)
    _clazz = clazz
    println("调用了辅助构造器2")
  }
}

object Demo08ScalaClassConstruct {
  def main(args: Array[String]): Unit = {
    val zs = new Demo08ScalaClassConstruct("001", "zs", 20)
    val xh = new Demo08ScalaClassConstruct("002", "xh", 18, "女")
    val xm = new Demo08ScalaClassConstruct("003", "xm", 22, "男", "文科一班")

    println(zs._id)
    println(zs._name)
    println(zs._gender)
    println(zs._clazz)

    println(xm._clazz)

  }

}
